import { SelectComponent } from './../shared/select/select.component';

import { Component, OnInit } from '@angular/core';
import { Globals } from './../../../shared/global';
import { DealerService } from '../services/dealer';
import { Router } from '@angular/router';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'ree-dealer-list',
  templateUrl: './dealer-list.component.html',
  styleUrls: ['./dealer-list.component.scss']
})
export class DealerListComponent implements OnInit {

  filter={
    dealerAccounts:'',
    companyName:''
  }
  dealersList = [];
  constructor(
    private dealerService: DealerService,
    public router: Router,
    private globals: Globals,
    private modalService: NzModalService
  ) { }

  ngOnInit() {
    this.getDealersList()
  }

  //获取经销商列表
  getDealersList() {
    this.dealerService.getDealersList().then(data => this.dealersList = data)
  }

  //打开验证公司对话框 加载modal
  createdealer() {
    const subscription = this.modalService.open({
      title: '关联供应商',
      wrapClassName: 'vertical-center-modal',
      content: SelectComponent,
      footer: false,
      componentParams: {
        type: 'dealer'
      }
    });
    subscription.subscribe(result => {
      if (result === "skip") { this.skipToCreate() }
    })
  }

  //跳转到创建经销商页
  skipToCreate() {
    this.router.navigate(["work/sell/create", "dealer"]);
    this.globals.paths.path.push({ name: "新增经销商", route: null })
  }

  //跳转到设备列表页，携带经销商账户数据
  skipToDevices(data) {
    //sessionStorage.setItem('dealerList-to-devices', data.dealerAccounts);
    this.router.navigate(["work/equipment/list", { id: data.dealerAccounts }]);
    this.globals.paths.path.push({ name: data.dealerAccounts + "的设备列表", route: null })
  }

  //跳转到绑定设备页，携带经销商账户数据
  skipToBind(data) {
    //sessionStorage.setItem('dealerList-to-bindDevice', data.dealerAccounts);
    this.router.navigate(["work/equipment/bind", data.dealerAccounts]);
    this.globals.paths.path.push({ name: "绑定设备", route: null }, { name: data.dealerAccounts, route: null })
  }

}
